package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import vo.Customer;
public class CustomerDao {
	private Connection conn=null;
	public void initConnection()throws Exception{	
		
		String driverClass="com.mysql.jdbc.Driver";
	    String url="jdbc:mysql://localhost:3306/vote?useSSL=false&useUnicode=true&characterEncoding=UTF-8";
	    String user="root";
	    String password="womenilu2580";
	    Class.forName(driverClass);
	    conn=DriverManager.getConnection(url,user,password);	   
	}
	//根据账号查询customer对象
	public Customer getCustomerByAccount(String account)throws Exception{
		Customer cus=null;
		initConnection();
		String sql="SELECT ADMIN,PD,CNAME FROM T_CUSTOMER WHERE ADMIN=?";
		PreparedStatement ps=conn.prepareStatement(sql);
		ps.setString(1, account);
		//System.out.println(account);
		ResultSet rs=ps.executeQuery();
		if(rs.next())
		{
			cus=new Customer();
			cus.setAccount(rs.getString("ADMIN"));
			cus.setPassword(rs.getString("PD"));
			cus.setCname(rs.getString("CNAME"));
			return cus;
		}
		conn.close();
		return null;
		
		
	}
}
